#!/bin/bash

# This wrapper script is necessary in order to avoid polluting the build
# systems with Android-specific quirks.

output_type=executable
output_path=

argv=()
while [[ $# > 0 ]]; do
  arg="$1"

  case "$arg" in
    -E)
      output_type=code
      ;;
    -c)
      output_type=object
      ;;
    -shared)
      output_type=shlib
      ;;
    -o)
      argv+=("-o")
      shift

      arg="$1"

      output_path="$arg"
      ;;
  esac

  argv+=("$arg")
  shift
done

if [[ $output_type = executable ]]; then
  argv+=("-Wl,-pie")
fi

"@driver@" "${argv[@]}" || exit $?

case $output_type in
  executable|shlib)
    "@elf_cleaner@" "$output_path"
    ;;
esac
